﻿@{
    ViewBag.Title = "订单在线支付";
    Layout = null;
}

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>订单在线支付</title>
</head>

<script type="text/javascript">
    window.history.forward(1);//禁止多次回退
    //调用微信JS api 支付
    function jsApiCall()
    {
        WeixinJSBridge.invoke(
             'getBrandWCPayRequest',
            @(Html.Raw(ViewBag.wxJsApiParam)), //josn串
             function (res)
             {
                 WeixinJSBridge.log(res);
                 if(res.err_msg == "get_brand_wcpay_request:ok")
                 {
                     //支付成功
                     var toUrl = @(Html.Raw(ViewBag.ToUrl));
                     if(toUrl != '')
                     {
                         location.href = toUrl;
                     }
                 }
                 else if(res.err_msg == "get_brand_wcpay_request:cancel")
                 {
                     //取消支付跳转地址
                     location.href='@(Html.Raw(ViewBag.CancelUrl))';
                 }
                 else
                 {
                     //支付失败
                     WeixinJSBridge.log(res.err_msg);
                     alert(res.err_code + res.err_desc + res.err_msg);
                     location.href="/GoldShopOrder/PaymentError";
                 }
             }
         );
     }

    function callpay()
    {
         if (typeof WeixinJSBridge == "undefined")
         {
             if (document.addEventListener)
             {
                 document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
             }
             else if (document.attachEvent)
             {
                 document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                 document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
             }
         }
         else
         {
             jsApiCall();
         }
     }

</script>

<body onload="callpay()">
    <div align="center">
        <span>正在请求微信支付......</span>
    </div>
</body>
</html>